/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tces.controller;


import com.tces.model.Role;
import com.tces.utils.ConnectionDAO;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;

/**
 *
 * @author arnolda
 */
public class RoleDAO  extends ConnectionDAO {

    private static final Logger log = Logger.getLogger(RoleDAO.class);

    public static List<Role> findAll() {
        List<Role> roleList = new ArrayList<Role>();
        try {

            String sql = "SELECT * FROM roles";

            PreparedStatement preparedStatement = getConnectionObject().prepareStatement(sql);
            //        preparedStatement.setInt(1, subjectOfferingID);
            log.info(preparedStatement.toString());
            ResultSet rs = preparedStatement.executeQuery();
            Role role;
            while (rs.next()) {
                role = new Role();
                role.setRoleID(rs.getInt("role_id"));
                role.setRoleName(rs.getString("role_name"));
                role.setRoleDescription(rs.getString("role_description"));
                roleList.add(role);
            }
            closeConnection(getConnectionObject());

        } catch (Exception ex) {
            closeConnection(getConnectionObject());
            log.error(ex);
        }
        return roleList;
    }
    
}
